package com.nbm.demo.mybatis;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class Main
{

        /**
         * @param args
         * @throws IOException 
         */
        public static void main(String[] args) throws IOException
        {
                String resource = "config/configuration.xml";
                Reader reader = Resources.getResourceAsReader(resource);
                SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
                SqlSession session = sqlSessionFactory.openSession();
               try{ 
                ScoreMapper mapper = session.getMapper(ScoreMapper.class);
                Score score=new Score();
                score.setId(6);
                score.setname("sp");
                score.setage(3);
                mapper.insertScore(score);
                System.out.println(score);
                session.commit();
               }catch(Exception e){
            	   e.printStackTrace();
               }finally{
                   session.close();
               }
        }

}
